/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package message.handler;
import java.util.*;
import message.*;
import net.*;
import structure.*;


/**
 *
 * @author antonio
 */

/********************************************************************************
 *                                                                              *
 * POSITION                                                                     *
 * MAC                                                                          *
 * |0x01|0x02|0x03|...                                                          *
 * SIGNAL                                                                       *
 * |0|0|0|10|23|....                                                            *
 * TOTAL                                                                        *
 * 50                                                                           *
 * END_POSITION                                                                 *
 *                                                                              *
 * ******************************************************************************/

/*
 *  MessagePositionHandler si occupa di creare il MessagePosition
 *  contenente le info di posizione sniffate da NetStumbler.
 *
 * */


public class MessagePositionHandler implements MessageHandler{

    private Scanner inputReader;

    public boolean handle(Scanner inputReader)
    {
        this.inputReader = inputReader;
        AccessPoint ap = new AccessPoint();

        while(true)
        {    
            String line = this.inputReader.nextLine();

            if(line.equals("END_POSITION"))
            {
                break;
            }
            else
            {
                if(line.equals("MAC"))
                {
                    String macLine = this.inputReader.nextLine();
                    ap.setMac(macLine);
                }
                else
                {
                    if(line.equals("SIGNAL"))
                    {
                        String signalLine = this.inputReader.nextLine();
                        ap.setSignal(signalLine);
                    }
                    else
                        if(line.equals("TOTAL"))
                        {
                            String totalSignal = this.inputReader.nextLine();
                            ap.setTotalSignal(totalSignal);
                        }
                }
            }
        }
        MessagePosition newPosition = new MessagePosition(ap);
        newPosition.estimatePosition();
        //newPosition.printStructure();
        

        return false;
    }
}